package com.ruoyi.web.controller.tool;

import com.ruoyi.common.core.redis.RedisLock;
import com.ruoyi.web.core.utils.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.concurrent.TimeUnit;

public class TestLockController {

    @Autowired
    private RedisLock redisLock;


    /**
     * 广播
     *
     * @param msg
     */
    @ResponseBody
    @RequestMapping("/lock")
    public void lock( @RequestBody Message msg) {
        String lockKey="cjq";

        // lockKey 锁实例key waitTime 最多等待时间 leaseTime 上锁后自动释放锁时间  unit 时间颗粒度
        redisLock.lock(lockKey);
        redisLock.tryLock(lockKey, 3L);
        redisLock.tryLock(lockKey, 3L, TimeUnit.SECONDS);
        redisLock.tryLock(lockKey, 2L, 1,  TimeUnit.SECONDS);
        redisLock.unlock(lockKey);

    }



}
